import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.util.Iterator;

import edu.cmu.minorthird.text.Annotator;
import edu.cmu.minorthird.text.MutableTextLabels;
import edu.cmu.minorthird.text.Span;
import edu.cmu.minorthird.text.TextBaseLoader;
import edu.cmu.minorthird.text.TextLabels;
import edu.cmu.minorthird.text.learn.AnnotatorLearner;
import edu.cmu.minorthird.text.learn.TextLabelsAnnotatorTeacher;
import edu.cmu.minorthird.ui.Recommended;


public class SolutionMinorthirdHMM {
	public static void main(String[] args) throws IOException, ParseException {
		File treino = new File("C:\\Users\\Goncalo\\Desktop\\SeminarPartial\\");
		TextBaseLoader loader = new TextBaseLoader();
		loader.load(treino);
		TextLabels treinoLabels = loader.getLabels();
		
		
		AnnotatorLearner learner = new Recommended.HMMAnnotatorLearner();
		learner.setAnnotationType("location");
		
		TextLabelsAnnotatorTeacher teacher = new TextLabelsAnnotatorTeacher(treinoLabels,"location");
		Annotator anotador = teacher.train(learner);
		
		File teste = new File("./resources/test/cmu.andrew.official.cmu-news-2457-0");
		TextBaseLoader loaderTest = new TextBaseLoader();
		loaderTest.load(teste);
		MutableTextLabels testeLabels = loaderTest.getLabels();
		
		anotador.annotate(testeLabels);
		
		Iterator<Span> iterDoc = testeLabels.getTextBase().documentSpanIterator();
		while(iterDoc.hasNext()){
			String docName = iterDoc.next().getDocumentId();
			for(Span troco : testeLabels.getTypeSet("location", docName)){
				System.out.println(troco.asString());
			}
		}
	}

}
